<?php
class WebsiteModel extends Model {
	
	public function getAllWebsites($userId = 'false') {
		$websites = array();
		$result = $this->selectAllIds('website', 'id_user =' . $userId);
		foreach ($result as $row) {
			$websites[] = new Website($row->id);
		}
		return $websites;
	}

    public function saveCommonAccess($websiteId, $userId, $access) {
        $queryString = sprintf("
            INSERT INTO
                `user_site_access`(`id_user`, `id_website`, `access`)
            VALUES
                (%d, %d, '%s')
        ", $userId, $websiteId, $access);
        return $this->_sqlInstance->query($queryString);
    }

	public function getCommonAccessWebsites($id) {
		$websites = array();
		$queryString = sprintf("
			SELECT
				`user_site_access`.`id_website`
			FROM
				`user_site_access`
			WHERE
				`user_site_access`.`id_user` = %d
		", $id);
		$result = $this->_sqlInstance->query($queryString);
		if($result) {
			foreach ($result as $row) {
				$websites[] = new Website($row->id_website);
			}
			return $websites;
		}
		return array();
	}

}